
---------- 技能使用管理
local _SkillEffTables = {}
local _skindex = 0

local SStatus_Normal = 0x01
local SStatus_Dead  = 0x02



Status_Stand    = 0x01
Status_Moved    = 0x02
Status_Attack   = 0x03
Status_Death    = 0x04

AnimSpriteBatchNodes = nil
local _func_onSkillUse = nil
local _func_onSkill_Update = nil
local _func_onAtk_Hurt = nil

mBattleObjectTable = {}


GetRoleProperty = function(rid)
    local _hpmax = Datas_Role[rid][PLife]
    local _def = Datas_Role[rid][PDef]
    local _atk = Datas_Role[rid][PAtk]
    local _atk_skill = _atk
    
    -- 技能附加属性
    local sktable = Datas_Role[rid][PSkill]
    if sktable ~= nil then
        for k, vskID in pairs(sktable) do
            local effinfo = SkillTable_Infos[vskID][PLevel][GetSkill(vskID)]
            if effinfo ~= nil then
                local tpe = effinfo[PEff][PType]
                local value = effinfo[PEff][PCount]
                if tpe == PSkill then
                    _atk_skill = value * _atk
                elseif tpe == PDef then
                    _def = _def + value
                elseif tpe == PLife then
                    _hpmax = _hpmax + value
                end
            end
        end
    end
    
    -- 装备附加属性
    if rid == Role_Soldier or rid == Role_Archer or rid == Role_Master then
        if GetItems(Datas_Role[rid].armor) > 0 then
            if rid == Role_Master then
                _hpmax = _hpmax + Datas_Role[rid].armorV
            else
                _def = _def + Datas_Role[rid].armorV
            end
        end
        if GetItems(Datas_Role[rid].weapon) > 0 then
            _atk = _atk + Datas_Role[rid].weaponV
        end
    end
    
    local obj = {
        atk=_atk,
        def=_def,
        atksk=_atk_skill,
        hp=_hpmax,
    }
    
    return obj
end


--------------------- 角色类
Player = {key=0,id=0,model=nil,info=nil,anim=nil, _lmove=nil, _latk=nil}
--这句是重定义元表的索引，必须要有，
Player.__index = Player
--模拟构造体，一般名称为new()
function Player:new(key, id, bshowUI)
    local self = {}   
    setmetatable(self, Player)   --必须要有
    self.key = key   
    self.id = id
    
    self.info = Datas_Role[id]
    local file = self.info[PModel]
    
    self._latk = 0  --上次攻击累积
    self._lmove = 0
    self._hpmax = self.info[PLife]
    self._def = self.info[PDef]
    self._atk = self.info[PAtk]
    self._atksp = self.info[PAtksp]
    self._movesp = nil
    self._bmove = false
    
    --攻击次数
    self.atkCut = 0
    
    --战斗状态(不同玩家角色切换
    self._bfight = true
    --- 无敌状态
    self.isWudi = false
    -- 暴走状态
    self.isBaozou = false
    
    self._iTeam = 0
    
    --- 技能,装备数值加成
    self._atk_skill = self._atk
    
    local proObj = GetRoleProperty(self.id)
    self._atk = proObj.atk
    self._def = proObj.def
    self._atk_skill = proObj.atksk
    self._hpmax = proObj.hp
    self._hp = self._hpmax
    
    print(self.id, self._atk, self._atk_skill)
    
    --BOSS技能伤害为普通的2倍
    if self.id == Mon_Leader then
        self._atk_skill = self._atk * 2
    end
    
    --print("_mode_",file,sktable)
    --print(string.format("HP:%i DEF:%i ATK:%i SATK:%i", self._hpmax, self._def, self._atk ,self._atk_skill))
    
    
    self._hp = self._hpmax
    
    
    self._fps_atk = self.info[PAtkFPS]
    self._fps_hurt = self.info[PHurtFps]
    
    if self._movesp == nil then
        self._movesp = MonsterMoveFps
    end
    --攻击次数
    self._count = self.info[PCount]
    if self._count == nil then
        self._count = 1
    end
    --攻击距离
    self._range = 60
    
    --状态
    self._status = Status_Moved
    
    ---CCArmature测试
    animName = file
    plistName = file
    self._myType = "zhanshi"
    
    local batchNode = AnimSpriteBatchNodes
    self.anim = CCArmature:create(animName, plistName, batchNode)
    local displayAnim = self.anim:getDisplay()
    --self.anim:setAnchorPoint(ccp(0.5, 0))
    self:moveStop()
    self.model = displayAnim
    --armature:getDisplay():setSkewX(50);
    --armature:getDisplay():setSkewY(-50);
    
    --上层显示
    self._layerUItop = CCLayer:create()
    --下显示
    self._layerUi = CCLayer:create()
    
    self._bshowUI = false
    if self._bshowUI then
    end
    
    if self.info[PScale] ~= nil then
        self.model:setScale(self.info[PScale])
    end
    
    -- 阴影
    self._SPyinYing = CCSprite:createWithSpriteFrameName("py_yingy.png")
    self._layerUi:addChild(self._SPyinYing)
    self._SPyinYing:setPosition(0,0)
    
    -- 当前动画
    self._lastSID = nil
    self._lastSF = nil
    self._lastST = 0
    
    self._anim = nil
    self:PlayAnim(Action_Stand)
    
    return self  
end

function Player:Show()
    self.anim:setVisible(true)
    self.model:setVisible(true)
    self._bfight = true
    
    self._layerUi:setVisible(true)
    self._layerUItop:setVisible(true)
end

function Player:Hide()
    self.anim:setVisible(false)
    self.model:setVisible(false)
    self._bfight = false
    
    self._layerUi:setVisible(false)
    self._layerUItop:setVisible(false)
end

--移除模型
function Player:Remove()
    self.model:stopAllActions()
    self.anim:stopAllActions()
    
    self.anim:setVisible(false)
    self.model:setVisible(false)
    self.anim = nil
    self.model = nil
    
    self:StopSound()
end
-- 拾取判断
function Player:isPick()
    local ispick = false
    return ispick
end
function Player:StopSound()
    if self._lastSID ~= nil then
        Stop_EffectByID(self._lastSID)
        self._lastSID = nil
    end
end
function Player:PlaySound()
    if self.info[PSound] ~= nil and self.info[PSound][self._anim] ~= nil then
        local sinfo = self.info[PSound][self._anim]
        
        self:StopSound()
        --播放音效
        self._lastSID = Play_Effect(sinfo.f)
        self._lastST = sinfo.t
        self._lastSF = sinfo.f
        
        if self._lastST == nil then
            self._lastST = 0
        end
    end
end
function Player:SoundLoop(dt)
    if self.info[PSound] ~= nil and self.info[PSound][self._anim] ~= nil then
        local sinfo = self.info[PSound][self._anim]
        if sinfo.t ~= nil then
            self._lastST = self._lastST - dt
            if self._lastSF ~= sinfo.f or self._lastST <= 0 then
                --重新播放
                self:PlaySound()
            end
        end
    end
end
-- 动画
function Player:PlayAnim(anim)
    --强制使用技能动画
    if anim ~= self._anim or anim == Action_Skill then
    
        self._anim = anim
        
        if self.id == Mon_Eyes and anim == Action_Stand then
            anim = Action_Move
        end
        self.anim:getAnimation():playTo(anim)
        
        self:PlaySound()
    end
end
-- 
function Player:setPosition(pos)
    if pos == nil then
        pos = ccp(0,0)
    end
    
    self.model:setPosition(ccp(pos.x, pos.y))
    self._layerUi:setPosition(ccp(pos.x, pos.y))
    
    self._layerUItop:setPosition(ccp(pos.x, RoleBegPosY))
end
function Player:getPosition()
    return self.model:getPosition()
end
function Player:updateAnim(dt)
    self.anim:update(dt)
end
-- 更新操作
function Player:update(dt)
    -- 每2秒移动一次
    self._lmove = self._lmove + dt
    self._latk = self._latk + dt
    
    -- 怪物向玩家位置移动
    if self._iTeam == 0 then
        local mypx, mypy = self:getPosition()
        -- 达到最终位置
        if self._status == Status_Moved then
            --远程移动过程中会攻击
            --print(self._latk - self.info[PAtkFPS],self._atksp )
            if self.info[PDmgType] == DamageType_Remote and self._latk >= self._atksp then
                self:onAttack()
                self._latk = 0
            end
            
            if self._anim == Action_Stand or self._anim == Action_Move then
                if mypx > MonsterToPosX then
                    self:PlayAnim(Action_Move)
                    self:setPosition(ccp(mypx - gdv(100 * dt), mypy))
                else
                    self:PlayAnim(Action_Stand)
                    self._status = Status_Attack
                end
            end
        elseif self._status == Status_Attack and self._anim == Action_Stand then
            if self._latk >= self._atksp then
                --boss随机技能与普通攻击
                local issk = false
                if self.id == Mon_Leader then
                    --local tpb = {true, false}
                    --issk = tpb[math.random(1,2)]
                    -- 6次普通攻击,1次技能攻击
                    if (self.atkCut+1)%7 == 0 then
                        issk = true
                    end
                end
                --攻击
                self:onAttack(issk)
                self._latk = 0
            end
        end
    end
    
    --音效音效
    self:SoundLoop(dt)
end
function Player:runAction(action)
    self.model:runAction(action)
end

--- 移动停止
function Player:moveStop()
    if self.anim ~= nil then
        self:PlayAnim(Action_Stand)
    end
end

-- 移动
function Player:moveTo(pos)
    local action = CCSequence:createWithTwoActions(
        CCMoveTo:create(MonsterMoveSpeed, pos), 
        CCCallFunc:create(function()
            self:moveStop()
            self._bmove = false
            self._latk = 0
            self._status = Status_Attack
        end
        )
    )
    self:runAction(action)
    self:PlayAnim(Action_Move)
    
    self._layerUi:runAction(CCMoveTo:create(MonsterMoveSpeed, ccp(pos.x, DWinSizeHeight*0.98)))
    self._layerUItop:runAction(CCMoveTo:create(MonsterMoveSpeed, ccp(pos.x, DWinSizeHeight*0.98)))
    
	self.lmove = 0
	self._bmove = true
end
--是否可以移动
function Player:hasMove()
    if not self._bmove then
        return true
    end
    return false
end
--受到伤害
function Player:onHurt(value)
    if self.isWudi then
        value = 0
    end
    
    local mx, my = self:getPosition()
    if self._hp - value < 0 then
        value = self._hp
    end
    self._hp = self._hp - value
    --print("hurt",self.id, self._hp, value)
    --受伤,出血
    if self._bshowUI then
        self._PlayerProgressHp:setPercentage(self._hp/self._hpmax * 100)
    end
    
    if self.id ~= Role_Soldier and self.id~=Role_Archer and self.id ~= Role_Master then
        self:PlayAnim(Action_Hurt)
        --受伤动画动作结束后恢复状态
        local action = CCSequence:createWithTwoActions(
            CCMoveTo:create(self._fps_hurt, ccp(self:getPosition())), 
            CCCallFunc:create(function()
                self:moveStop()
            end
            )
        )
        self:runAction(action)
    else
        self:setPosition(ccp(PlayerBegPosX, RoleBegPosY))
        for k,sobj in pairs({self, self._layerUi, self._layerUItop}) do
            if sobj ~= nil then
                -----玩家角色受到伤害,身后移动即可
                local action = CCSequence:createWithTwoActions(
                    CCMoveBy:create(0.2, ccp(-10, 0)), 
                    CCCallFunc:create(function()
                        --v:runAction(CCMoveTo:create(0.1, ccp(PlayerBegPosX, RoleBegPosY)))
                        sobj:runAction(CCSequence:createWithTwoActions(CCMoveBy:create(0.2, ccp(10, 0)), CCCallFunc:create(function()
                            self:setPosition(ccp(PlayerBegPosX, RoleBegPosY))
                        end)))
                    end)
                )
                sobj:runAction(action)
            end
        end
    end
    
    --伤害数字
    local _lblSoul = GameNumbers:new(vNumberHurt)
    _lblSoul:addLayer(CCDirector:sharedDirector():getRunningScene())
    _lblSoul:setNumber(-value)
    _lblSoul:setPosition(ccp(mx, my))
    _lblSoul:runAction_MoveBy(1.0, ccp(0,100), true)
    --print(-value,mx,my)
    
    
    if self._hp <= 0 then
        return true
    end
    return false
end
--是否可以攻击
function Player:hasAttack()
    if self._latk >= self._atksp then
        return true
    end
    return false
end
--攻击
function Player:onAttack(bskill, monster)
    --if self.id ~= Role_Soldier and self.id~=Role_Archer and self.id ~= Role_Master then
    --else
    --    self:runAction(CCMoveTo:create(0.1, ccp(PlayerBegPosX, RoleBegPosY)))
    --end
    
    self.atkCut = self.atkCut + 1
    
    local useAction = Action_Attack
    if bskill then
        self:PlayAnim(Action_Skill)
        self._fps_atk = self.info[PSkillFPS]
        self._fps_hurt = self.info[PSkillHFps]
        useAction = Action_Skill
    else
        self:PlayAnim(Action_Attack)
        self._fps_atk = self.info[PAtkFPS]
        self._fps_hurt = self.info[PHurtFps]
    end
    
    self._latk = 0
    -- 动作结束后恢复状态
    local action = CCSequence:createWithTwoActions(
        CCMoveTo:create(self._fps_atk, ccp(self:getPosition())), 
        CCCallFunc:create(function()
            self:moveStop()
        end
        )
    )
    self:runAction(action)
    
    -- 如果是技能则飞出技能,否则直接伤害
    local onfangshe = false
    if self.info[PSkillEffs] ~= nil then
        for k,v in pairs(self.info[PSkillEffs]) do
            if v == useAction then
                onfangshe = true
                break
            end
        end
    end
    
    local hurtfunc = nil
    if onfangshe then
        hurtfunc = function()
            _func_onSkillUse(self, useAction, bskill)
        end
    else
        hurtfunc = function()
            sortFunc = function(a, b)
                if a == nil or b == nil then
                    return false
                end
                local vlenght1 = ccpLength(ccp(a:getPosition()))
                local vlenght2 = ccpLength(ccp(b:getPosition()))
                return vlenght2 < vlenght1 
            end
            table.sort(mBattleObjectTable, sortFunc)
            
            local maxTag = self._count
            for k, mon in pairs(mBattleObjectTable) do
                -- 不同阵营,并且在范围内,并且可战斗
                --print(self._iTeam, mon._iTeam , self:inRange(mon) , mon._bfight)
                if self._iTeam ~= mon._iTeam and self:inRange(mon) and mon._bfight then
                    _func_onAtk_Hurt(self, mon, bskill)
                    maxTag = maxTag - 1
                    if maxTag <= 0 then
                        break
                    end
                end
            end
        end
    end
    
    local action = nil
    ----- BOSS专有动作
    if self.id == Mon_Leader and bskill then
        self.model:stopAllActions()
        
        local mypx ,mypy = self:getPosition()
            
        --print("BOSS jump")
        self:PlayAnim("skill")
        local action = CCMoveTo:create(0.2, ccp(mypx + 250, mypy))
        self:runAction(CCSequence:createWithTwoActions(action, CCCallFunc:create(function()
            self:PlayAnim("skill0")
            --原地移动
            action = CCSequence:createWithTwoActions(
                CCMoveBy:create(0.5, ccp(0, 0)), 
                CCCallFunc:create(function()
                    -- 向玩家冲去,时间后受伤
                    action = CCSequence:createWithTwoActions(
                        CCMoveTo:create(self._fps_hurt, ccp(PlayerBegPosX, mypy)), 
                        CCCallFunc:create(function()
                            hurtfunc()
                            --self:moveStop()
                            
                            self:PlayAnim(Action_Move)
                            action = CCSequence:createWithTwoActions(
                            CCMoveTo:create(0.3, ccp(mypx, mypy)), 
                            CCCallFunc:create(function()
                                self:moveStop()
                            end))
                            self:runAction(action)
                            
                            self._layerUi:runAction(CCMoveTo:create(0.3, ccp(mypx, mypy)))
                        end))
                    self:runAction(action)
                    self._layerUi:runAction(CCMoveTo:create(self._fps_hurt, ccp(PlayerBegPosX, mypy)))
                end))
            self:runAction(action)
        end)))
        self._layerUi:runAction(CCMoveTo:create(0.2, ccp(mypx + 250, mypy)))
    else
        --受伤时间到后受到伤害
        action = CCSequence:createWithTwoActions(
            CCMoveTo:create(self._fps_hurt, ccp(self:getPosition())), 
            CCCallFunc:create(hurtfunc)
            )
        self:runAction(action)
    end
end
--是否在攻击范围内
function Player:inRange(monsert)
    local mpx , mpy = monsert:getPosition()
    local px, py = self:getPosition()
    --- 远程,或者接近近战范围
    if self.info[PDmgType] == DamageType_Remote or math.abs(mpx - px) < AttackRange then
        return true
    end
    return false
end



------------------ 战场类
BattleField = {layer=nil, _index=0, _bpx=0, _bpy=0}
--这句是重定义元表的索引，必须要有
BattleField.__index = BattleField
function BattleField:new()
    local self={}
    setmetatable(self, BattleField)   --必须要有
    self.layer = CCLayer:create()
    mBattleObjectTable = {}
    self._index=0
    
    self._bpx = 0
    self._bpy = 799
    
    local batchNode = CCSpriteBatchNode:create(GetPathRes("fmodel/role.png"), 100)
    AnimSpriteBatchNodes = batchNode

    self.layer:addChild(AnimSpriteBatchNodes,1)
    
    _SkillEffTables = {}
    
    return self
end

function BattleField:getKey()
    self._index = self._index + 1
    --return string.format("mon_%d",self._index)
    return self._index
end

function BattleField:createRole(id, pos, bshowUI)
    if bshowUI == nil then
        bshowUI = true
    end

    local key = self:getKey()
    local obj = Player:new(key, id, bshowUI)
    self.layer:addChild(obj._layerUi)
    self.layer:addChild(obj._layerUItop,3)
    
    obj:setPosition(pos)
    
    table.insert(mBattleObjectTable, obj)
    return obj
end

function BattleField:deleteRole(obj)
    if obj == nil then
        return
    end
    
    table.foreach(mBattleObjectTable, function(k, _obj)
        if _obj.key == obj.key then
            self.layer:removeChild(obj._layerUi, true)
            obj:Remove()
            mBattleObjectTable[k] = nil
        end
    end)
end


function BattleField:update(dt, batction)
    table.foreach(mBattleObjectTable, function(k, obj)
        obj:updateAnim(dt)
        if batction == nil then
            batction = true
        end
        
        if batction then
            obj:update(dt)
        end
    end)
    
    _func_onSkill_Update(dt, self)
end

function BattleField:Remove()
end


local _func_remove_anim = function(obj)
    CCDirector:sharedDirector():getRunningScene():removeChild(obj, true)
end
local _func_remove_layer = function(cobj)
    _SkillEffTables[cobj.id] = nil
    CCDirector:sharedDirector():getRunningScene():removeChild(cobj.layer, true)
end
local _func_remove_layer_back = function(tag)
    if _SkillEffTables[tag] ~= nil then
        _func_remove_layer(_SkillEffTables[tag])
    end
end


local SkillMaxPX = DWinSizeWidth + 100
local SkillMinPX = -100

_func_onSkillUse = function(cobj, action, bskill)
    local mlayer = CCLayer:create()
    mlayer:setPosition(0,0)
    CCDirector:sharedDirector():getRunningScene():addChild(mlayer,5)
    
    local ty = 0
    local img = nil
    local file = nil
    if cobj.id == Role_Soldier then ----- 战士
        -- 效果显示
        img = CCSprite:createWithSpriteFrameName("zs_skill_eff.png")
        img:setPosition(ccp(PlayerBegPosX + gdv(55), RoleBegPosY))
        img:setAnchorPoint(ccp(1, 0))
        img:setScale(Datas_Role[cobj.id][PScale])
        -- 向右边飞去
        local act = CCMoveTo:create(gdvc(1),ccp(SkillMaxPX, RoleBegPosY))
        
        img:runAction(CCRepeatForever:create(CCSequence:createWithTwoActions(act, CCCallFunc:create(_func_remove_layer_back))))
    elseif cobj.id == Role_Archer then  ------弓箭手
        file = "arrowN.png"
        ty = RoleBegPosY + gdv(19)
        if action == Action_Skill then
            file = "arrowS.png"
            ty = RoleBegPosY + gdv(15)
        end
        -- 效果显示
        img = CCSprite:createWithSpriteFrameName(file)
        img:setPosition(ccp(PlayerBegPosX + gdv(62), ty))
        img:setAnchorPoint(ccp(1, 0))
        img:setScale(Datas_Role[cobj.id][PScale])
        -- 向右边飞去
        local act = CCMoveTo:create(gdvc(1),ccp(SkillMaxPX, ty))
        img:runAction(CCRepeatForever:create(CCSequence:createWithTwoActions(act, CCCallFunc:create(_func_remove_layer_back))))
    elseif cobj.id == Role_Master then ------法师
        img = GFunc_CreateAnimation("mofashi_01", 2, 4)
        
        ty = RoleBegPosY + gdv(48)
        img:setPosition(ccp(PlayerBegPosX + gdv(80), ty))
        img:setAnchorPoint(ccp(1, 0.5))
        
        -- 原地放大
        img:setScale(Datas_Role[cobj.id][PScale] * 0.2)
        img:runAction(CCScaleTo:create(0.2, Datas_Role[cobj.id][PScale]))
        
        local array = CCArray:create()
        --array:addObject(CCMoveBy:create(gdvc(0.2),ccp(0,0))) --原地放大
        array:addObject(CCMoveTo:create(gdvc(1),ccp(SkillMaxPX, ty)))
        --img:runAction(CCRepeatForever:create(CCSequence:create(array)))
        --
        --local act = CCMoveTo:create(gdvc(1),ccp(SkillMaxPX, ty))
        img:runAction(CCRepeatForever:create(CCSequence:createWithTwoActions(CCSequence:create(array), CCCallFunc:create(_func_remove_layer_back))))
    elseif cobj.id == Mon_Eyes then ---------- 眼球怪
        -- 效果显示
        img = CCSprite:createWithSpriteFrameName("eyes_012.png")
        local bpx, bpy = cobj:getPosition()
        img:setPosition(ccp(bpx - gdv(30), RoleBegPosY + gdv(70)))
        img:setAnchorPoint(ccp(1, 0))
        img:setScale(Datas_Role[cobj.id][PScale])
        -- 向左下边飞去
        local act = CCMoveTo:create(gdvc(0.5),ccp(SkillMinPX, RoleBegPosY))
        img:runAction(CCRepeatForever:create(CCSequence:createWithTwoActions(act, CCCallFunc:create(_func_remove_layer_back))))
    elseif cobj.id == Mon_Eagle then  -----敌人法师
        -- 效果显示
        img = CCSprite:createWithSpriteFrameName("difa_026.png")
        local bpx, bpy = cobj:getPosition()
        ty = RoleBegPosY + gdv(40)
        img:setPosition(ccp(bpx - gdv(30), ty))
        img:setAnchorPoint(ccp(0, 0.5))
        img:setScale(Datas_Role[cobj.id][PScale])
        
        
        img:setScale(Datas_Role[cobj.id][PScale] * 0.2)
        img:runAction(CCScaleTo:create(0.2, Datas_Role[cobj.id][PScale]))
        
        -- 向左下边飞去
        local act = CCMoveTo:create(gdvc(0.5),ccp(SkillMinPX, ty))
        img:runAction(CCRepeatForever:create(CCSequence:createWithTwoActions(act, CCCallFunc:create(_func_remove_layer_back))))
    end
    
    if img then
        _skindex = _skindex + 1
        local obj = {
            layer = mlayer,
            img = img,
            rid = cobj.id,
            id = _skindex,
            s = SStatus_Normal,
            obj = cobj,
            bsk = bskill,
        }
        _SkillEffTables[obj.id] = obj
        
        mlayer:addChild(img,0,obj.id)
    end
end

_func_onAtk_Hurt = function(cobj, cmon, bskill)
    if cobj == nil or cmon == nil then
        return
    end

    local vattack = cobj._atk
    if bskill then
        vattack = cobj._atk_skill
    end
    
    if cobj.isBaozou then
        vattack = vattack * 2
    end
    
    --伤害
    local vhurt = vattack - cmon._def
    if vhurt < 10 then
        vhurt = 10
    end
    cmon:onHurt(vhurt)
    return
end

_func_onSkill_Ends = function(cobj, cmon)
    --爆炸效果
    if cobj.rid == Mon_Eagle then
        local px, py = cobj.img:getPosition()
        img = GFunc_CreateAnimation("difa_00", 1, 5, 1, nil, _func_remove_anim)
        img:setPosition(ccp(px + gdv(30), py-gdv(30)))
        img:setAnchorPoint(ccp(0.5, 0))
        img:setScale(Datas_Role[cobj.rid][PScale])
        CCDirector:sharedDirector():getRunningScene():addChild(img)
    end
    
    _func_remove_layer(cobj)
    _func_onAtk_Hurt(cobj.obj, cmon, cobj.bsk)
end

_func_onSkill_Update = function(dt, mybattle)
    table.foreach(_SkillEffTables, function(k, cobj)
        local spx, spy = cobj.img:getPosition()
        local obj = cobj.obj
        
        -- 更新效果
        if spx <= SkillMinPX or spx >= SkillMaxPX then
            _func_remove_layer(cobj)
        else
            if obj.id ~= Role_Soldier and obj.id ~= Role_Archer and obj.id ~= Role_Master then
                -- 判断碰撞
                for mi, cmon in pairs(mBattleObjectTable) do
                    local mpx, mpy = cmon:getPosition()
                    if obj._iTeam ~= cmon._iTeam and mpx+10 > spx and cmon._bfight then
                        _func_onSkill_Ends(cobj, cmon)
                        break
                    end
                end
            else
                -- 判断碰撞
                for mi, cmon in pairs(mBattleObjectTable) do
                    local mpx, mpy = cmon:getPosition()
                    if obj._iTeam ~= cmon._iTeam and mpx < spx and cmon._bfight then
                        _func_onSkill_Ends(cobj, cmon)
                        break
                    end
                end
            end
        end
    end)
end




